<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>百度语音 -> 文字转语音</title>
</head>
<body>

<script>
function fun(text) {
    var zhText = text;
    // 文本长度必须小于1024字节
    zhText = encodeURI(zhText);

    // 语速，取值0-9，默认为5中语速
    var spd = 5;
    // 音调，取值0-9，默认为5中语调
    var pit = 1;

    document.write("<audio autoplay=\"autoplay\">");
    document.write("<source src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=" + spd + "&text="+ zhText +"\" type=\"audio/mpeg\">");
    // document.write("<embed height=\"0\" width=\"0\" src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text="+ zhText +"\">");
    document.write("</audio>");
}

setTimeout(function() {
    fun("呵呵");
}, 500);
</script>
</body>
</html>